<?php

namespace App\Model;

use App\Model\BaseModel;

class AdminRole extends BaseModel
{
    protected $table = "admin_roles";

    /**
     * 当前角色的所有权限
     */
    public function permissions(){
    	return $this->belongsToMany(\App\Model\AdminPermission::class,'admin_permission_role','permission_id','role_id');
    }

    /**
     * 给角色授权
     */
    public function grantPermission($permission){
    	return $this->permissions()->save($permission);
    }

    /**
     * 删除permission和role的关联
     */
    public function deletePermission($permission){
        return $this->permissions()->detach($permission);
    }

}